package concrete;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;

public class Test {
	public static void main(String[] args) throws InterruptedException {
		ConcurrentLinkedQueue<Map<String, Integer>> queue = new ConcurrentLinkedQueue<>();
		// List<Map<String, Integer>> queue = new ArrayList<>();
		Map<String, Integer> map1 = new HashMap<>();
		map1.put("k1", 1);
		queue.add(map1);
		Map<String, Integer> map2 = new HashMap<>();
		map2.put("k2", 2);
		queue.add(map2);
		Map<String, Integer> map3 = new HashMap<>();
		map3.put("k3", 3);
		queue.add(map3);
		listenThread lThread = new Test().new listenThread(queue);
		lThread.start();
		Thread.sleep(1000l);
		map1.put("k1", 0);
		queue.remove(map1);
		queue.remove(map2);
		queue.remove(map3);
		lThread.go = true;

		ConcurrentLinkedQueue<String> queue2 = new ConcurrentLinkedQueue<>();
		queue2.iterator();
	}

	class listenThread extends Thread {
		boolean go = false;
		ConcurrentLinkedQueue<Map<String, Integer>> queue;
		// List<Map<String, Integer>> queue;

		public listenThread(ConcurrentLinkedQueue<Map<String, Integer>> queue) {
			// public listenThread(List<Map<String, Integer>> queue) {
			// TODO Auto-generated constructor stub
			this.queue = queue;
		}

		public void run() {
			Iterator<Map<String, Integer>> iterator = queue.iterator();
			while (true) {
				if (go) {
					while (iterator.hasNext()) {
						System.out.println(iterator.next().values().iterator().next());
					}
					System.out.println("======");
					Iterator<Map<String, Integer>> iterator2 = queue.iterator();
					while (iterator2.hasNext()) {
						System.out.println(iterator2.next().values().iterator().next());
					}
				}
				try {
					Thread.sleep(10l);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
